package cn.com.aisat.android.videoshow.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.IntentSender.SendIntentException;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.com.aisat.android.videoshow.R;
import cn.com.aisat.android.videoshow.TvDramaActivity;
import cn.com.aisat.android.videoshow.data.TVMovieItem;

public class TvPaperAdapter extends BaseAdapter{
	List<TVMovieItem> items;
	
	Context context;
	LayoutInflater inflater;
	
	public TvPaperAdapter(Context context,List<TVMovieItem> list){
		this.context=context;
		this.items=list;
				
	}
	
	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		inflater=LayoutInflater.from(context);
		convertView=inflater.inflate(R.layout.gridview_item, null);
		ImageView image = (ImageView) convertView.findViewById(R.id.gridview_item_imageview);
		TextView text = (TextView) convertView.findViewById(R.id.gridview_item_text);
		
		image.setBackgroundResource(R.drawable.move_no_pic);
		/*String imagepath=items.get(position).getImagepath();
		///////////////////////
		Bitmap mBitmap=null;
		// 直接获取图片：
		try {
		//sendMSG(Declare.START, "正在加载图片......");
			Log.i("whc", "正在加载图片");
		mBitmap = TvDramaActivity.getImage(imagepath);
		//sendMSG(Declare.STOP, "");
		Log.i("whc", "正在加载图片STOP");
		} catch (Exception e) {
		// TODO Auto-generated catch block
		//sendMSG(Declare.ERROR, e.getMessage());
		}
		//这里带有一个简单的滚动条，表示当前程序正在执行，通过发送消息的方式实现的，具体不再写了，那个消息无头此核心代码的实现.
		//在加载完成后执行：
		if(mBitmap!=null){
			image.setImageBitmap(mBitmap);
		}else{
			image.setBackgroundResource(R.drawable.move_no_pic);
		}*/
	text.setText(items.get(position).getName());

		return convertView;
	}
	
}